package lxs.swift.operation.match;


import org.jetbrains.annotations.NotNull;

import java.util.Objects;

public class BiMatch<T, C1 extends Case<T>, C2 extends Case<T>> {
    private final T value;

    public BiMatch(T value) {
        this.value = value;
    }

    public <R, TD extends Todo<T, R>> R of(@NotNull Item<T, R, C1, TD> i1, @NotNull Item<T, R, C2, TD> i2) {
        Objects.requireNonNull(i1);
        Objects.requireNonNull(i2);
        if (i1.tCase.test(value)) {
            return i1.tTodo.todo(value);
        }
        if (i2.tCase.test(value)) {
            return i2.tTodo.todo(value);
        }
        throw new RuntimeException("cannot be matched exhaustively");
    }
}
